package com.southwind.springboottest.study.java中正则表达式;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @description：TODO
 * @author： HXG
 * @create： 2024/4/19 9:48
 */


public class Main3 {
    public static void main(String[] args) {
        String text = "The cat and the rat sat on the mat.";
        String pattern = "cat";
        String replacement = "dog";
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(text);
        String replacedText = m.replaceAll(replacement);
        System.out.println("Replaced text: " + replacedText);

    }
}

